using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Security.AccessControl;

namespace Caramel.IO
{
	public class WindowsDirectoryInfo : IDirectoryInfo
	{
		private DirectoryInfo _directoryInfo;

		public WindowsDirectoryInfo(DirectoryInfo directoryInfo)
		{
			_directoryInfo = directoryInfo;
		}

		#region IDirectoryInfo Members

		public void Create(DirectorySecurity directorySecurity)
		{
			_directoryInfo.Create(directorySecurity);
		}

		public IDirectoryInfo CreateSubdirectory(string path, DirectorySecurity directorySecurity)
		{
			return
				new WindowsDirectoryInfo(
					_directoryInfo.
						CreateSubdirectory(
							path,
							directorySecurity
						)
				);
		}

		public void Delete(bool recursive)
		{
			_directoryInfo.Delete(recursive);
		}

		public IEnumerable<IDirectoryInfo> GetDirectories(string searchPattern, SearchOption searchOption)
		{
			return
				_directoryInfo.
					GetDirectories(searchPattern, searchOption).
					Select(d => new WindowsDirectoryInfo(d)).
					Cast<IDirectoryInfo>();
		}

		public IEnumerable<IFileInfo> GetFiles(string searchPattern, SearchOption searchOption)
		{
			return
				_directoryInfo.
					GetFiles(searchPattern, searchOption).
					Select(f => new WindowsFileInfo(f)).
					Cast<IFileInfo>();
		}

		public void MoveTo(string destDirName)
		{
			_directoryInfo.MoveTo(destDirName);
		}

		public IDirectoryInfo Parent
		{
			get 
			{
				return new WindowsDirectoryInfo(_directoryInfo.Parent);
			}
		}

		public IDirectoryInfo Root
		{
			get
			{
				return new WindowsDirectoryInfo(_directoryInfo.Root);
			}
		}

		#endregion
	}
}
